<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <title>用户表</title>
    <div th:replace="common/link::header"></div>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <form class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">用户昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="nickName" placeholder="请输入用户昵称" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" placeholder="请输入手机号" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" placeholder="请输入邮箱" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                    <button type="reset" class="layui-btn layui-btn-primary" lay-submit lay-filter="reset">重置</button>
                </div>
            </div>
        </form>
        <div class="layui-card-body">
            <table id="userTable" lay-filter="userTable"></table>
            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">

                </div>
            </script>
            <script type="text/html" id="tableBar">
                <a sec:authorize="hasAuthority('user:info')" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="info"><i class="layui-icon layui-icon-edit"></i>详情</a>
            </script>
        </div>
    </div>
</div>
<div th:replace="common/script::footer"></div>
<script th:inline="javascript">
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table','crud'], function() {
        let $ = layui.$,
            form = layui.form,
            table = layui.table,
            crud = layui.crud;
        //监听搜索
        form.on('submit(search)', function(data) {
            let field = data.field;
            //执行重载
            table.reload('userTable', {
                where: field
            });
        });
        //监听重置
        form.on('submit(reset)', function(data) {
            Object.keys(data.field).forEach(key => (data.field[key] = ''));
            table.reload('userTable', {
                where: data.field
            });
        });
        // 查询列表接口
        table.render({
            elem: '#userTable'
            ,toolbar: '#toolbar'
            ,height: 'full-110'
            ,url:  ctx + '/app/user/page'
            ,cellMinWidth: 80
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID', hide:true},
                {field: 'nickName', title: '昵称'},
                {field: 'avatar', title: "头像", templet: function (d) { return crud.showImg(d.avatar); }},
                {field: 'appType', title: "登录方式"},
                {field: 'gender', title: "性别",templet: function (d) { return crud.getDictValue('sex',d.gender);}},
                {field: 'birthday', title: '生日'},
                {field: 'mobile', title: '手机号'},
                {field: 'email', title: '邮箱'},
                {toolbar: '#tableBar', title: '操作', width: 300, align:'center',fixed: 'right'}
            ]]
        });
        //头工具栏事件
        table.on('toolbar(userTable)', function(obj) {
            let checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data;
        });
        //监听行工具事件
        table.on('tool(userTable)', function(obj) {
            let data = obj.data //获得当前行数据
                ,layEvent = obj.event;
            if(layEvent === 'info') {
                active.infoView(data.id);
            }
        });
        /* 触发弹层 */
        let active = {
            /**
             * 用户详情
             * @param id id
             * */
            infoView: function(id) {
                layer.open({
                    type: 2
                    ,shade: 0.3
                    ,title: '用户详情'
                    ,content: ctx + '/app/user/infoPage/' + id
                    ,maxmin: true
                    ,scrollbar: false
                    ,area: ['100%', '100%']
                    ,btn: ['关闭']
                    ,yes: function(index, layero){
                        layer.closeAll();
                    }
                });
            }
        }
    });
</script>
</body>
</html>
